package com.tenc.utils;

import com.tenc.bean.BaseEntity;
import com.tenc.exception.GlobalExceptionHandler;
import com.tenc.exception.ResponseException;
import com.tenc.pojo.ErrorJson;
import com.tenc.vo.ApiRest;
import com.tenc.vo.WechatEnum;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Alan
 * @date 2021/7/20
 * @description 公共工具类
 * @ClassName CommonUtils
 */
public class CommonUtils {


    /**
     * 获取公共对象
     * @return access_token
     */
    public static Map<String,String> get(){
        Map<String,String> map = new HashMap<>();
        map.put("access_token",RedisUtil.get("acToken"));
        return map;
    }

    public static ErrorJson express (ErrorJson json) {
        if(json.getErrcode().equals(0)){ //成功获取直接返回
            return json;
        }else{
            throw new ResponseException(WechatEnum.wechatEnum(json.getErrcode()).getMessage());
        }
    }

    public static BaseEntity baseExpress(BaseEntity json){
        if(json.getErrcode().equals(0)){ //成功获取直接返回
            return json;
        }else{
            throw new ResponseException(WechatEnum.wechatEnum(json.getErrcode()).getMessage());
        }
    }
}
